/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.orm.refinedclasses;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

import org.testis.orm.classes.T_bed_devicegroup;
import org.testis.orm.classes.T_bed_devicegroup_details;
import org.testis.utils.middleware.DeviceGroupDataHandler;

/**
 * 
 * @author selcuk
 */
public class DeviceGroupRefined extends TestBedItem {

    private T_bed_devicegroup m_reference;

    public DeviceGroupRefined(T_bed_devicegroup reference) {
	super();
	setReference(reference);
    }

    public int getId() {
	return m_reference.getId();
    }

    public String getName() {
	return m_reference.getName();
	//
    }

    private void setReference(T_bed_devicegroup reference) {
	if (reference == null) {
	    throw new NullPointerException();
	}
	m_reference = reference;
    }

    @Override
    public String toString() {
	return getName();
    }

    @Override
    public String getTypeName() {
	return "DeviceGroup";
    }

    public LinkedList<DeviceGroupDetailRefined> getDetails() {
	LinkedList<DeviceGroupDetailRefined> result = new LinkedList<DeviceGroupDetailRefined>();
	T_bed_devicegroup_details[] details = m_reference.t_bed_devicegroup_details
		.toArray();
	if (details != null) {
	    for (int i = 0; i < details.length; i++) {
		result.add(new DeviceGroupDetailRefined(details[i]));
	    }
	}
	return result;
    }

    public static DeviceGroupRefined[] getDeviceGroupArray() {
	Collection coll = DeviceGroupDataHandler.newInstance()
		.getDeviceGroups();
	DeviceGroupRefined[] result = new DeviceGroupRefined[coll.size()];
	int idx = 0;
	for (Iterator it = coll.iterator(); it.hasNext(); idx++) {
	    T_bed_devicegroup ref = (T_bed_devicegroup) it.next();
	    result[idx] = new DeviceGroupRefined(ref);
	}
	return result;
    }

    public static LinkedList<DeviceGroupRefined> getDeviceGroupList() {
	LinkedList<DeviceGroupRefined> result = new LinkedList<DeviceGroupRefined>();
	DeviceGroupRefined[] arr = getDeviceGroupArray();
	for (int i = 0; i < arr.length; i++) {
	    result.add(arr[i]);
	}
	return result;
    }

    public static HashMap getDeviceGroupMap() {
	HashMap result = new HashMap();
	DeviceGroupRefined[] arr = getDeviceGroupArray();
	for (int i = 0; i < arr.length; i++) {
	    result.put(arr[i].getId(), arr[i]);
	}
	return result;
    }
}
